<template>
	<div>
		<el-form ref="form" :model="form" label-width="100px">
			<el-form-item label="客户" prop="userName">
				<el-select v-model="form.userName" placeholder="请选择客户" clearable :style="{width: '100%'}" @change="change()">
					<el-option v-for="(item, index) in userData" :key="index" :label="item.userName"
						:value="item.userName" :disabled="item.disabled"></el-option>
				</el-select>

			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<el-select v-model="form.sex">
					<el-option v-for="(item,index) in sexData" :key="index" :value="item.value" :label="item.label">
					</el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="外出事由" prop="goCause">
				<el-input v-model="form.goCause"></el-input>
			</el-form-item>
			<el-form-item label="外出时间" prop="goTime">
				<el-date-picker v-model="form.goTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
					:style="{width: '100%'}" placeholder="请输入时间" clearable>
				</el-date-picker>
			</el-form-item>
			<el-form-item label="预计回院时间" prop="backTime">
				<el-date-picker v-model="form.backTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
					:style="{width: '100%'}" placeholder="请输入时间" clearable>
				</el-date-picker>
			</el-form-item>

			<el-form-item label="陪同人" prop="orderlies">
				<el-input v-model="form.orderlies"></el-input>
			</el-form-item>
			<el-form-item label="与老人关系" prop="relation">
				<el-input v-model="form.relation"></el-input>
			</el-form-item>
			<el-form-item label="陪同人电话" prop="phoneNum">
				<el-input v-model="form.phoneNum"></el-input>
			</el-form-item>
			<el-form-item label="备注" prop="note">
				<el-input v-model="form.note"></el-input>
			</el-form-item>


			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	export default {
		name: 'goToRegisterEdit',
		components: {

		},
		props: [
			'showEdit',
			'goId',
			'editid'
		],
		data() {
			return {
				form: {},
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				// isupdate: false,
				url: '/goToRegister/save',
				registerlevel: [],
				depts: [],
				userData: [],
			}
		},
		created() {
			// this.init()
			console.log("this.editid:" + this.editid)
			if (this.editid) {
				this.axios.get('/goToRegister/toedit', response => {
					console.log(response.obj);
					this.form = response.obj;
				}, {
					id: this.editid
				})
			}

			this.axios.get('/user/findUser', res => {
				this.userData = res.obj
			})
		},
		methods: {
			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			},
			change() {
				for (let i = 0; i < this.userData.length; i++) {
					if (this.userData[i].userName == this.form.userName) {
						this.form.sex = this.userData[i].sex;
						this.form.age = this.userData[i].age;
						this.form.fileNum = this.userData[i].fileNum;
						break;
					}
				}
			}
		},
		
	}
</script>

<style>

</style>
